package com.example.koizzi.ad20180517_news;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.koizzi.ad20180517_news.bean.MyUser;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class LoginCountActivity extends AppCompatActivity {
    private Button btnLg;
    private EditText edUN;
    private EditText edPW;
    private String ccc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logincount);
        initView();
    }

    private void initView() {
        btnLg = findViewById(R.id.btn_Lg);
        edUN = findViewById(R.id.ed_UN);
        edPW = findViewById(R.id.ed_PW);

        btnLg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ccc = getIntent().getStringExtra("CCC");
                MyUser user = new MyUser();
                user.setUsername(edUN.getText().toString());
                user.setPassword(edPW.getText().toString());
                user.login(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        Toast.makeText(LoginCountActivity.this,"登录成功", Toast.LENGTH_SHORT).show();
                        Intent info = new Intent(LoginCountActivity.this,ViewNewsActivity.class);
                        info.putExtra("TEL" , String.valueOf(edUN));
                        info.putExtra("NEWS_URL1" , ccc);
                        startActivity(info);
                        finish();
                    }
                });
            }
        });
    }
}
